﻿//Copyright (C) Riwut Libinuko, 2010 - Ideas For Free
//http://blog.libinuko.com

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SharePointZip.Controller;
using ICSharpCode.SharpZipLib.Zip;
using Microsoft.SharePoint;
using SharePointZip.Base;

namespace SharePointZip.Tools
{
    /// <summary>
    /// Implementation of <see cref="SharpZipLibCompressorBase&lt;TSource&gt;"/> to compress <see cref="Microsoft.SharePoint.SPFolder"/>.
    /// </summary>
    public class SPFolderCompressor : SharpZipLibCompressorBase<SPFolder>
    {
        /// <summary>
        /// Create compressed <see cref="Microsoft.SharePoint.SPFolder"/> using <see cref="ZipOutputStream"/>.
        /// </summary>
        /// <param name="zipEngine">Active compression engine</param>
        /// <param name="objSrc">SPFolder to be compressed</param>
        public override void CreateCompressedStream(ZipOutputStream zipEngine, SPFolder objSrc)
        {
            var compressor = ServiceLocator.Instance.GetService<ICompress<ZipOutputStream, SPFile>>();
            foreach (SPFile spFile in objSrc.Files)
            {
                compressor.CreateCompressedStream(zipEngine, spFile);
            }

            foreach (SPFolder spFolder in objSrc.SubFolders)
            {
                this.CreateCompressedStream(zipEngine, spFolder);
            }

        }
    }
}
